﻿using System;
using System.Text;
using System.Data;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MxWeiXinPF.Common;
using System.Web.UI.HtmlControls;


namespace MxWeiXinPF.Web.admin.weixin
{
    public partial class myweixinlist : MxWeiXinPF.Web.UI.ManagePage
    {
        private MxWeiXinPF.BLL.wx_userweixin bll = new MxWeiXinPF.BLL.wx_userweixin();
        protected HtmlForm form1;
        protected HtmlHead Head1;
        protected string keywords = string.Empty;
        protected Label lblHasNum;
        protected Label lblTotNum;
        protected LinkButton lbtnSearch;
        protected int page = 1;
        protected int pageSize = 20;
        protected Repeater rptList;
        protected int totalCount;
        protected TextBox txtKeywords;

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            base.Response.Redirect(Utils.CombUrlTxt("myweixinlist.aspx", "keywords={0}", new string[] { this.txtKeywords.Text }));
        }

        protected string CombSqlTxt(string _keywords)
        {
            StringBuilder builder = new StringBuilder();
            _keywords = _keywords.Replace("'", "");
            if (!string.IsNullOrEmpty(_keywords))
            {
                builder.Append(" and (wxName like  '%" + _keywords + "%' or weixinCode like '%" + _keywords + "%')");
            }
            return builder.ToString();
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            this.keywords = MXRequest.GetQueryString("keywords");
            if (!this.Page.IsPostBack)
            {
                this.RptBind(this.CombSqlTxt(this.keywords), "createDate desc,id desc");
            }
        }

        private void RptBind(string _strWhere, string _orderby)
        {
            MxWeiXinPF.Model.manager adminInfo = base.GetAdminInfo();
            _strWhere = string.Concat(new object[] { "uId=", adminInfo.parentid, " and isDelete=0 ", _strWhere, " order by ", _orderby });
            this.txtKeywords.Text = this.keywords;
            IList<MxWeiXinPF.Model.wx_userweixin> modelList = this.bll.GetModelList(_strWhere);
            if (modelList != null)
            {
                this.lblHasNum.Text = modelList.Count.ToString();
            }
            this.lblTotNum.Text = adminInfo.wxNum.ToString();
            this.rptList.DataSource = modelList;
            this.rptList.DataBind();
        }

        protected void rptList_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            string commandName = e.CommandName;
            if ((commandName != null) && (commandName == "toIndex"))
            {
                int id = int.Parse(e.CommandArgument.ToString());
                MxWeiXinPF.Model.wx_userweixin model = this.bll.GetModel(id);
                this.Session["nowweixin"] = model;
                Utils.WriteCookie("nowweixinId", "MxWeiXinPF", e.CommandArgument.ToString());
                base.Response.Write("<script>parent.location.href='/admin/index.aspx'</script>");
            }
        }
    }
}